package com.dys.controller;

import com.dys.common.ResponseResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 疾风
 * @ClassName: RoleController
 * @Description: 角色控制器
 * @CreateDate: 2024/12/17
 * @Version: v1.0.0
 */
@RestController
@RequestMapping(value = {"/role"})
public class RoleController {

    /**
     * 当前用户是common角色,并且具有system:role:list或者system:user:list权限
     */
    @PreAuthorize(value = "hasRole('common') AND hasAnyAuthority('system:user:list','system:role:list')")
    @GetMapping(value = {"/hasRoleAndAuthority"})
    public ResponseResult<String> hasRoleAndAuthority() {
        return new ResponseResult<>(200, "响应成功", "当前用户是common角色,并且具有system:role:list或者system:user:list权限");
    }

    /**
     * 当前用户拥有admin或者common角色,或者具有system:role:list权限
     */
    @PreAuthorize(value = "hasAnyRole('admin','common') OR hasAuthority('system:role:list')")
    @GetMapping(value = {"/hasRoleOrAuthority"})
    public ResponseResult<String> hasRoleOrAuthority() {
        return new ResponseResult<>(200, "响应成功", "当前用户拥有admin或者common角色,或者具有system:role:list权限");
    }
}
